<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Flashy {
	function Flashy()
	{
		session_start();
	}
	
	public function save_flash($name, $value)
	{
		if (!isset($_SESSION['flash']))
			$_SESSION['flash'] = array(); // instantiate the flash array
		
		$_SESSION['flash'][$name] = $value;
	}
	
	public function flash_exists($name)
	{
		if (isset($_SESSION['flash'][$name]))
			return true;
		else
			return false;
	}
	
	public function get_flash($name)
	{
		if ($this->flash_exists($name))
		{
			$str = $_SESSION['flash'][$name];
			$this->expire_flash($name);
			return $str;
		}
		else
			return false;
	}
	
	public function expire_flash($name)
	{
		if (isset($_SESSION['flash'][$name]))
			unset($_SESSION['flash'][$name]);
	}
	
	public function garbage_collect()
	{
		// kill any remaining flash entries at the end of the request
		//unset($_SESSION['flash']);
		//$_SESSION['flash'] = array();
	}
}
?>